<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0" />
        <title>3种创建对象的方法</title>
    </head>
    <body>
        <script>
            // 方法1的定义对象的方法， 字面量方式
            var camera = {
                strName: "美颜相机",
                width: 1920,
                height: 1080,
                pic : function picture(){
                    console.log("拍照");
                }
            }
            console.log(camera.strName);
            console.log(camera.width);
            camera.strName = "MM-Camera"
            console.log(camera.strName);
            camera.pic();

            // 方法2 采用new Object
            cam = new Object;
            cam.strName = "mm相机";
            cam.height = 1080;
            cam.width = 1920;
            cam.pic = function picture(){
                console.log("mm拍照");
            }
            cam.pic();

            // 方法3 构造函数方法,  格式： 
            // var 类名 = function 函数名（参数列表） 
            // { 
            //     this.属性 = 参数;
            //     this.方法 = function name(params) {
            //     } 
            // }
            var Camera = function came(strName, width, height) {
                this.strName = strName;
                this.width = width;
                this.height = height;
                this.pic = function picture(type) {
                    console.log(type);
                }
            }

            var mycam = new Camera("单反相机", 1920, 1080);
            console.log(mycam.height);
            mycam.height = 9600;
            console.log(mycam.height);
            
            mycam.pic("山水照");
            
        </script>
    </body>
</html>
